<?php
	if(!empty($staffDetailarray)){
	   $this->Paginator->options(array(
	         'update' => '#divUpdate',
	         'evalScripts' => true, 
	      ));
	}
  echo $this->session->flash(); ?>
<div class="file">
     <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#686550">
        <tr class="heading">
            <td width="5%" valign="top" bgcolor="#708089"><?php echo __('S.NO'); ?></td>
            <td valign="top" bgcolor="#708089"><?php echo $this->Paginator->sort('name', __('E_NAME', true)); ?></td>
            <td valign="top" bgcolor="#708089"><?php echo __('C_NAME'); ?></td>
            <!-- <td valign="top" bgcolor="#708089"><?php //echo __('SERVICE_GROUP'); ?></td>
            <td valign="top" bgcolor="#708089"><?php //echo __('SERVICE_UNIT'); ?></td> -->
            <td valign="top" bgcolor="#708089"><?php echo __('ROLE'); ?></td>
            <td valign="top" bgcolor="#708089"><?php echo $this->Paginator->sort('created', __('CREATED', true)); ?></td>
            <td valign="top" bgcolor="#708089"><?php echo __('ACTION') ?></td>
        </tr>
  
        <?php
	
        if(isset($staffDetailarray) && ($staffDetailarray!="")){
          $i=0;
          foreach($staffDetailarray as $arrayDetail){
		if($arrayDetail['User']['active_status'] == 1){
                        $statusCls = "active-img";
			$actionMsg = __('DEACTIVATE',true);
			$statusMsg = __('CONFRIM_DEACT_MESSAGE',true);
		}else{
			$statusCls = "deactive-img";
			$actionMsg = __('ACTIVATE',true);
			$statusMsg = __('CONFRIM_ACT_MESSAGE',true);
		}
          ?>
        <tr>
            <td bgcolor="#FFFFFF"><?php echo $i + 1 ?></td>
            <td bgcolor="#FFFFFF"><?php echo $arrayDetail['User']['e_name'] ?></td>
            <td bgcolor="#FFFFFF"><?php echo $arrayDetail['User']['c_name'] ?></td>
            <!--<td bgcolor="#FFFFFF"><?php /*
	    if(isset($arrayDetail['ServiceUnit']['ServiceGroup'])){
		//echo $arrayDetail['ServiceUnit']['ServiceGroup']['group_name'];
		$unitName = $arrayDetail['ServiceUnit']['unit_name'];
	    }else{
		//echo "N/A";
		$unitName = "N/A";
	    }*/
	     ?></td>
            <td bgcolor="#FFFFFF"><?php //echo $unitName; ?></td> -->
            <td bgcolor="#FFFFFF"><?php echo $arrayDetail['Role']['role_name'] ?></td>

            <td bgcolor="#FFFFFF">
                <?php
                if (isset($arrayDetail['User']['created']) && ($arrayDetail['User']['created'] != "0000-00-00 00:00:00")) {
                    echo date('M j, Y', strtotime($arrayDetail['User']['created']));
                } else {
                    echo "NA";
                }
                ?>
            </td>
            <td bgcolor="#FFFFFF">&nbsp;<?php
		if(!$roleId){//No checks for superadmin
                    echo $this->html->link($this->Html->image('icons/16/edit_user.png'), array(
                        'controller' => 'users',
                        'action' => 'updatestaff',
                        $arrayDetail['User']['id']), array(
                        'alt' => __('EDIT', true),
                        'title' => __('EDIT', true),
                        'escape'=>false)
                    );
                    echo '&nbsp;&nbsp;';
                    echo $this->html->link($this->Html->image('icons/16/permissions.png'), array(
                        'controller' => 'users',
                        'action' => 'change_unit_permission',
                        $arrayDetail['User']['id']), array(
                        'alt' => __('UNIT_PERMISSION', true),
                        'title' => __('UNIT_PERMISSION', true),
                        'escape'=>false)
                    );
                    echo '&nbsp;&nbsp;';
                    echo $this->html->link($this->Html->image('icons/16/cross.png'), array(
                        'controller' => 'users',
                        'action' => 'delete',
                        $arrayDetail['User']['id']), array(
                            'alt' => __('DELETE', true),
                            'title' => __('DELETE', true),
                            'escape'=>false,
                            'confirm' => 'Are you sure to delete user. You can\'t revert it back'
                        )
                    );
		}else{
                    if($showUserEditURL){
                        echo $this->html->link($this->Html->image('icons/16/edit_user.png'), array(
                            'controller' => 'users',
                            'action' => 'updatestaff',
                            $arrayDetail['User']['id']), array(
                            'alt' => __('EDIT', true),
                            'title' => __('EDIT', true),
                            'escape'=>false)
                        );
                        echo '&nbsp;&nbsp;';
                        echo $this->html->link($this->Html->image('icons/16/permissions.png'), array(
                            'controller' => 'users',
                            'action' => 'change_unit_permission',
                            $arrayDetail['User']['id']), array(
                            'alt' => __('UNIT_PERMISSION', true),
                            'title' => __('UNIT_PERMISSION', true),
                            'escape'=>false)
                        );
                    }
                    if($showUserDeleteURL){
                        echo $this->html->link($this->Html->image('icons/16/cross.png'), array(
                            'controller' => 'users',
                            'action' => 'delete',
                            $arrayDetail['User']['id']), array(
                            'alt' => __('DELETE', true),
                            'title' => __('DELETE', true),
                            'escape'=>false,
                            'confirm' => 'Are you sure to delete user. You can\'t revert it back')
                        );
                    }
		}
			

		/*
		if ($arrayDetail['User']['active_status'] != 2) {

                    $mess = __("CONFRIM_MESSAGE", true);
                    echo $this->Js->link('', array('controller' => 'staffs', 'action' => 'updateStaffStatus', 'delete', $arrayDetail['User']['id']), array('update' => 'divUpdate', 'alt' => __('DELETE', true), 'title' => __('DELETE', true), 'class' => 'icon_16 delete-img'), $mess);


                    echo $this->Js->link('', array('controller' => 'staffs', 'action' => 'updateStaffStatus', $actionMsg, $arrayDetail['User']['id']), array('update' => 'divUpdate', 'alt' => ucwords($actionMsg), 'title' => ucwords($actionMsg), 'class' => 'icon_16 ' . $statusCls), $statusMsg);
                } else {
                    
                }

                if ($userType == 1) {
                    echo $this->html->link('', array('controller' => 'staffs', 'action' => 'viewLog', $arrayDetail['User']['id']), array('alt' => __('VIEW_LOG', true), 'title' => __('VIEW_LOG', true), 'class' => 'icon_16 edit-img', 'escape' => false));
                }
                */
                ?>
            </td>
        </tr>  
          <?php
          $i++;
          }
        }
         if(empty($staffDetailarray)){
        ?>
        <tr>
            <td bgcolor="#FFFFFF" colspan="7" align="center">
        <?php
               echo __("NO_RECORD_MESSAGE",true);
            ?>
            </td>
        </tr>
        <?php
         }
         else{?>
	 <tr>
	    <td colspan="8" bgcolor="#ffffff">
            <div class="pagination">
            <ul>
            <li>
            <?php
		echo $this->Element('pagination');
            ?>
            </li>
               
            </ul>
          </div>
	    </td>
	 </tr>
	 
         <?php }
         ?>
	 
	 <tr bgcolor="#ffffff">
	    <td colspan="8" valign="top">
	       <table width="70%">
		  <tr>
		     <td width="10%">
			<b><?php echo __('LEGENDS');?> :- </b> 
		     </td>
		     <td width="15%">
			<?php echo $this->html->image('/img/icons/16/edit_user.png');?>

			<?php echo __('EDIT_USER');?>
		     </td>
                     <td width="15%">
			<?php echo $this->html->image('/img/icons/16/permissions.png');?>

			<?php echo __('EDIT_UNIT_PERMISSION');?>
		     </td>
		     <!--
		     <td width="15%">
			<?php //echo $this->html->image('/img/icons/16/cross.png');?>
			<?php //echo __('DELETE');?>
		     </td>
		     <td width="15%">
			<?php //echo $this->html->image('/img/icons/16/active.gif');?>
			<?php //echo __('ACTIVATE');?>
		     </td>
		     <td width="20%">
			<?php //echo $this->html->image('/img/icons/16/deactive.gif');?>
			<?php //echo __('DEACTIVATE');?>
		     </td> -->
		  </tr>
		</table>
	    </td>
	 </tr>
	 
    </table>
     
</div>
<?php echo $this->Js->writeBuffer();?>